Change prototype to match cairo_set_source_surface().
authorOwen Taylor <otaylor@redhat.com>
Sat, 7 May 2005 18:51:18 +0000 (18:51 +0000)
committerOwen Taylor <otaylor@src.gnome.org>
Sat, 7 May 2005 18:51:18 +0000 (18:51 +0000)
2005-05-07  Owen Taylor  <otaylor@redhat.com>

        * gdk/gdkpixbuf-render.c gdk/gdkpixbuf.h (gdk_pixbuf_set_as_cairo_source):
        Change prototype to match cairo_set_source_surface().

        * gdk/gdkdraw.c gdk/gdkgc.c gdk/gdkpixbuf-render.c gdk/gdkwindow.c
        gtk/gtkhsv.c tests/testcairo.c.

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-8
gdk/gdkdraw.c
gdk/gdkgc.c
gdk/gdkpixbuf-render.c
gdk/gdkpixbuf.h
gdk/gdkwindow.c
gtk/gtkhsv.c
tests/testcairo.c

index 14188fddb6ceeefd5e16dd8427e829270f8cb34f..16b3dac9a958286cd2c44ea634f938b2db6c4ecc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2005-05-07  Owen Taylor  <otaylor@redhat.com>
+
+       * gdk/gdkpixbuf-render.c gdk/gdkpixbuf.h (gdk_pixbuf_set_as_cairo_source): 
+       Change prototype to match cairo_set_source_surface().
+
+       * gdk/gdkdraw.c gdk/gdkgc.c gdk/gdkpixbuf-render.c gdk/gdkwindow.c
+       gtk/gtkhsv.c tests/testcairo.c.
+
 2005-05-06  Federico Mena Quintero  <federico@ximian.com>
 
        Merged from gtk-2-6:
index 14188fddb6ceeefd5e16dd8427e829270f8cb34f..16b3dac9a958286cd2c44ea634f938b2db6c4ecc 100644 (file)
@@ -1,3 +1,11 @@
+2005-05-07  Owen Taylor  <otaylor@redhat.com>
+
+       * gdk/gdkpixbuf-render.c gdk/gdkpixbuf.h (gdk_pixbuf_set_as_cairo_source): 
+       Change prototype to match cairo_set_source_surface().
+
+       * gdk/gdkdraw.c gdk/gdkgc.c gdk/gdkpixbuf-render.c gdk/gdkwindow.c
+       gtk/gtkhsv.c tests/testcairo.c.
+
 2005-05-06  Federico Mena Quintero  <federico@ximian.com>
 
        Merged from gtk-2-6:
index 14188fddb6ceeefd5e16dd8427e829270f8cb34f..16b3dac9a958286cd2c44ea634f938b2db6c4ecc 100644 (file)
@@ -1,3 +1,11 @@
+2005-05-07  Owen Taylor  <otaylor@redhat.com>
+
+       * gdk/gdkpixbuf-render.c gdk/gdkpixbuf.h (gdk_pixbuf_set_as_cairo_source): 
+       Change prototype to match cairo_set_source_surface().
+
+       * gdk/gdkdraw.c gdk/gdkgc.c gdk/gdkpixbuf-render.c gdk/gdkwindow.c
+       gtk/gtkhsv.c tests/testcairo.c.
+
 2005-05-06  Federico Mena Quintero  <federico@ximian.com>
 
        Merged from gtk-2-6:
index ca0950d2c4635a7df87e52c5597a209ce458ee3d..3269668b194430dada12e106ba945c99ab92fb61 100644 (file)
@@ -884,16 +884,16 @@ real_draw_glyphs (GdkDrawable      *drawable,
 
   if (matrix)
     {
-      cairo_matrix_t *cairo_matrix;
-
-      cairo_matrix = cairo_matrix_create ();
-      cairo_matrix_set_affine (cairo_matrix,
-                              matrix->xx, matrix->yx,
-                              matrix->xy, matrix->yy,
-                              matrix->x0, matrix->y0);
+      cairo_matrix_t cairo_matrix;
+
+      cairo_matrix.xx = matrix->xx;
+      cairo_matrix.yx = matrix->yx;
+      cairo_matrix.xy = matrix->xy;
+      cairo_matrix.yy = matrix->yy;
+      cairo_matrix.x0 = matrix->x0;
+      cairo_matrix.y0 = matrix->y0;
       
-      cairo_set_matrix (cr, cairo_matrix);
-      cairo_matrix_destroy (cairo_matrix);
+      cairo_set_matrix (cr, &cairo_matrix);
     }
 
   cairo_move_to (cr, x, y);
@@ -1304,11 +1304,9 @@ gdk_drawable_create_cairo_context (GdkDrawable *drawable)
     
   g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
 
-  cr = cairo_create ();
-
   surface = _gdk_drawable_ref_cairo_surface (drawable);
-  if (surface)
-    cairo_set_target_surface (cr, surface);
+  cr = cairo_create (surface);
+  cairo_surface_destroy (surface);
 
   return cr;
 }
index 50179d4110322a66e665e18e6fc7ea7b040f7815..8c386938cc0b8e9559bc85a72dc2f01900bcac52 100644 (file)
@@ -1044,14 +1044,13 @@ make_stipple_tile_surface (cairo_t   *cr,
   
   alpha_surface = _gdk_drawable_ref_cairo_surface (stipple);
   
-  surface = cairo_surface_create_similar (cairo_get_target_surface (cr),
+  surface = cairo_surface_create_similar (cairo_get_target (cr),
                                          CAIRO_FORMAT_ARGB32,
                                          width, height);
 
-  tmp_cr = cairo_create ();
-  cairo_set_target_surface (tmp_cr, surface);
+  tmp_cr = cairo_create (surface);
   
-  cairo_set_operator (tmp_cr, CAIRO_OPERATOR_SRC);
+  cairo_set_operator (tmp_cr, CAIRO_OPERATOR_SOURCE);
  
   if (background)
       gdk_cairo_set_source_color (tmp_cr, background);
index 6e3891f7587fb3f1f42b47a9c4913f9f0bcca88a..d8eda5eb694fdb4d34cf9911b2ec646008056005 100644 (file)
@@ -333,14 +333,18 @@ gdk_pixbuf_render_pixmap_and_mask_for_colormap (GdkPixbuf   *pixbuf,
  * gdk_pixbuf_set_as_cairo_source:
  * @pixbuf: a #GdkPixbuf
  * @cr: a #Cairo context
+ * @pixbuf_x: X coordinate of location to place upper left corner of @pixbuf
+ * @pixbuf_y: Y coordinate of location to place upper left corner of @pixbuf
  * 
  * Sets the given pixbuf as the source pattern for the Cairo context.
  * The pattern has an extend mode of %CAIRO_EXTEND_NONE and is aligned
- * so that the origin of @pixbuf is at the current point.
+ * so that the origin of @pixbuf is @pixbuf_x, @pixbuf_y
  **/
 void
 gdk_pixbuf_set_as_cairo_source (GdkPixbuf *pixbuf,
-                               cairo_t   *cr)
+                               cairo_t   *cr,
+                               double     pixbuf_x,
+                               double     pixbuf_y)
 {
   gint width = gdk_pixbuf_get_width (pixbuf);
   gint height = gdk_pixbuf_get_height (pixbuf);
@@ -350,10 +354,7 @@ gdk_pixbuf_set_as_cairo_source (GdkPixbuf *pixbuf,
   guchar *cairo_pixels;
   cairo_format_t format;
   cairo_surface_t *surface;
-  cairo_pattern_t *pattern;
   static const cairo_user_data_key_t key;
-  cairo_matrix_t *matrix;
-  double x, y;
   int j;
 
   if (n_channels == 3)
@@ -424,17 +425,7 @@ gdk_pixbuf_set_as_cairo_source (GdkPixbuf *pixbuf,
       cairo_pixels += 4 * width;
     }
 
-  pattern = cairo_pattern_create_for_surface (surface);
-  cairo_surface_destroy (surface);
-  
-  cairo_current_point (cr, &x, &y);
-  matrix = cairo_matrix_create ();
-  cairo_matrix_translate (matrix, -x, -y);
-  cairo_pattern_set_matrix (pattern, matrix);
-  cairo_matrix_destroy (matrix);
-
-  cairo_set_source (cr, pattern);
-  cairo_pattern_destroy (pattern);
+  cairo_set_source_surface (cr, surface, pixbuf_x, pixbuf_y);
 }
 
 #define __GDK_PIXBUF_RENDER_C__
index 04f00a7eefda5167ac233f2f0997d399646c0ad4..aa5b4acba2cf58a239f35382d24d1928bd54ee75 100644 (file)
@@ -81,7 +81,9 @@ GdkPixbuf *gdk_pixbuf_get_from_image    (GdkPixbuf   *dest,
                                          int          height);
 
 void gdk_pixbuf_set_as_cairo_source (GdkPixbuf *pixbuf,
-                                    cairo_t   *cr);
+                                    cairo_t   *cr,
+                                    double     pixbuf_x,
+                                    double     pixbuf_y);
 
 G_END_DECLS
 
index 145e27519413e936488e2ae3ceb31bf463e1887b..87280a50522dbf12fcf5f6d54b677e0ca17ebbf4 100644 (file)
@@ -1748,10 +1748,9 @@ gdk_window_set_bg_pattern (GdkWindow      *window,
 
       if (x_offset != 0 || y_offset)
        {
-         cairo_matrix_t *matrix = cairo_matrix_create ();
-         cairo_matrix_translate (matrix, x_offset, y_offset);
-         cairo_pattern_set_matrix (pattern, matrix);
-         cairo_matrix_destroy (matrix);
+         cairo_matrix_t matrix;
+         cairo_matrix_init_translate (&matrix, x_offset, y_offset);
+         cairo_pattern_set_matrix (pattern, &matrix);
        }
 
       cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
@@ -1795,8 +1794,7 @@ gdk_window_clear_backing_rect (GdkWindow *window,
   if (GDK_WINDOW_DESTROYED (window))
     return;
 
-  cr = cairo_create ();
-  cairo_set_target_surface (cr, paint->surface);
+  cr = cairo_create (paint->surface);
 
   gdk_window_set_bg_pattern (window, cr, 0, 0);
 
index 36908b707ffb27b482f4b03d4041c57541f5497c..20ca50c63c73f4841667354efe9f6e7d88dee65e 100644 (file)
@@ -917,26 +917,6 @@ gtk_hsv_motion (GtkWidget      *widget,
 
 /* Redrawing */
 
-static void
-set_source_surface (cairo_t         *cr,
-                   cairo_surface_t *surface)
-{
-  cairo_pattern_t *pattern;
-  cairo_matrix_t *matrix;
-  double x, y;
-
-  pattern = cairo_pattern_create_for_surface (surface);
-  
-  cairo_current_point (cr, &x, &y);
-  matrix = cairo_matrix_create ();
-  cairo_matrix_translate (matrix, -x, -y);
-  cairo_pattern_set_matrix (pattern, matrix);
-  cairo_matrix_destroy (matrix);
-
-  cairo_set_source (cr, pattern);
-  cairo_pattern_destroy (pattern);
-}
-
 /* Paints the hue ring */
 static void
 paint_ring (GtkHSV      *hsv,
@@ -1018,8 +998,7 @@ paint_ring (GtkHSV      *hsv,
   /* Now draw the value marker onto the source image, so that it
    * will get properly clipped at the edges of the ring
    */
-  source_cr = cairo_create ();
-  cairo_set_target_surface (source_cr, source);
+  source_cr = cairo_create (source);
   
   r = priv->h;
   g = 1.0;
@@ -1042,8 +1021,7 @@ paint_ring (GtkHSV      *hsv,
 
   cairo_save (cr);
     
-  cairo_move_to (cr, x, y);
-  set_source_surface (cr, source);
+  cairo_set_source_surface (cr, source, x, y);
   cairo_surface_destroy (source);
 
   cairo_set_line_width (cr, priv->ring_width);
@@ -1220,8 +1198,7 @@ paint_triangle (GtkHSV      *hsv,
   
   /* Draw a triangle with the image as a source */
 
-  cairo_move_to (cr, x, y);
-  set_source_surface (cr, source);
+  cairo_set_source_surface (cr, source, x, y);
   cairo_surface_destroy (source);
   
   cairo_move_to (cr, x1, y1);
index 141bb8517f98c4e08ae374626d22f2a292fcf038..06257cd9af37fc4139359c2861b062e78d1b8163 100644 (file)
@@ -29,10 +29,7 @@ oval_path (cairo_t *cr,
            double xc, double yc,
            double xr, double yr)
 {
-  cairo_matrix_t *matrix;
-
-  matrix = cairo_matrix_create ();
-  cairo_current_matrix (cr, matrix);
+  cairo_save (cr);
 
   cairo_translate (cr, xc, yc);
   cairo_scale (cr, 1.0, yr / xr);
@@ -43,8 +40,7 @@ oval_path (cairo_t *cr,
             0, 2 * G_PI);
   cairo_close_path (cr);
 
-  cairo_set_matrix (cr, matrix);
-  cairo_matrix_destroy (matrix);
+  cairo_restore (cr);
 }
 
 /* Create a path that is a circular oval with radii xr, yr at xc,
@@ -125,25 +121,26 @@ draw (cairo_t *cr,
       int      height)
 {
   cairo_surface_t *overlay, *punch, *circles;
+  cairo_t *overlay_cr, *punch_cr, *circles_cr;
 
   /* Fill the background */
   double radius = 0.5 * (width < height ? width : height) - 10;
   double xc = width / 2.;
   double yc = height / 2.;
 
-  overlay = cairo_surface_create_similar (cairo_current_target_surface (cr),
+  overlay = cairo_surface_create_similar (cairo_get_target (cr),
                                          CAIRO_FORMAT_ARGB32,
                                          width, height);
   if (overlay == NULL)
     return;
 
-  punch = cairo_surface_create_similar (cairo_current_target_surface (cr),
+  punch = cairo_surface_create_similar (cairo_get_target (cr),
                                        CAIRO_FORMAT_A8,
                                        width, height);
   if (punch == NULL)
     return;
 
-  circles = cairo_surface_create_similar (cairo_current_target_surface (cr),
+  circles = cairo_surface_create_similar (cairo_get_target (cr),
                                          CAIRO_FORMAT_ARGB32,
                                          width, height);
   if (circles == NULL)
@@ -151,47 +148,39 @@ draw (cairo_t *cr,
     
   fill_checks (cr, 0, 0, width, height);
 
-  cairo_save (cr);
-  cairo_set_target_surface (cr, overlay);
-  cairo_identity_matrix (cr);
-
   /* Draw a black circle on the overlay
    */
-  cairo_set_source_rgb (cr, 0., 0., 0.);
-  oval_path (cr, xc, yc, radius, radius);
-  cairo_fill (cr);
-
-  cairo_save (cr);
-  cairo_set_target_surface (cr, punch);
+  overlay_cr = cairo_create (overlay);
+  cairo_set_source_rgb (overlay_cr, 0., 0., 0.);
+  oval_path (overlay_cr, xc, yc, radius, radius);
+  cairo_fill (overlay_cr);
 
   /* Draw 3 circles to the punch surface, then cut
    * that out of the main circle in the overlay
    */
-  draw_3circles (cr, xc, yc, radius, 1.0);
-
-  cairo_restore (cr);
+  punch_cr = cairo_create (punch);
+  draw_3circles (punch_cr, xc, yc, radius, 1.0);
+  cairo_destroy (punch_cr);
 
-  cairo_set_operator (cr, CAIRO_OPERATOR_OUT_REVERSE);
-  cairo_set_source_surface (cr, punch, 0, 0);
-  cairo_paint (cr);
+  cairo_set_operator (overlay_cr, CAIRO_OPERATOR_DEST_OUT);
+  cairo_set_source_surface (overlay_cr, punch, 0, 0);
+  cairo_paint (overlay_cr);
 
   /* Now draw the 3 circles in a subgroup again
    * at half intensity, and use OperatorAdd to join up
    * without seams.
    */
-  cairo_save (cr);
-  cairo_set_target_surface (cr, circles);
-
-  cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
-  draw_3circles (cr, xc, yc, radius, 0.5);
-
-  cairo_restore (cr);
+  circles_cr = cairo_create (circles);
+  
+  cairo_set_operator (circles_cr, CAIRO_OPERATOR_OVER);
+  draw_3circles (circles_cr, xc, yc, radius, 0.5);
+  cairo_destroy (circles_cr);
 
-  cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
-  cairo_set_source_surface (cr, circles, 0, 0);
-  cairo_paint (cr);
+  cairo_set_operator (overlay_cr, CAIRO_OPERATOR_ADD);
+  cairo_set_source_surface (overlay_cr, circles, 0, 0);
+  cairo_paint (overlay_cr);
 
-  cairo_restore (cr);
+  cairo_destroy (overlay_cr);
 
   cairo_set_source_surface (cr, overlay, 0, 0);
   cairo_paint (cr);